// Package controllers
// @Title  default.go
// @Description  默认控制器
// @Author  小斌 (时间 格式是2021/12/02  10:20)
// @Update  小斌 (时间 格式是2021/12/02  10:20)
package controllers

import (
	"beego-admin/models"
	"beego-admin/service"
	"github.com/astaxie/beego"
)

type MainController struct {
	BaseController
}

func (this *MainController) Index() {
	//获取图片host
	imageHost := beego.AppConfig.String("qiniu::imageHost")

	//查询轮播图
	list,_ := models.GetUseCarouselList()

	type CarouselObj struct{
		ImageUrl                 string    `json:"image_url"`
		Url               string `json:"url"`
	}
	var returnData[]CarouselObj
	for _, v := range *list {
		tmpParam := CarouselObj{imageHost + v.ImageUrl,v.Url}
		returnData = append(returnData, tmpParam)
	}

	//查询首页推荐列表
	queryParams := models.ArticleQueryParams{
		PageSize: 6,
		Page:  1,
		HomeRecommend:2,
	}

	articleList,_,_ := models.GetArticleList(queryParams)
	articleData := service.ArticleListFormat(articleList)
	this.Data["carousel_list"] = returnData
	this.Data["article_list"] = articleData
	this.Data["page_title"] = "首页"
	this.TplName = "index/index.tpl"
}
